﻿using HslCommunication.Core;
using PLC.Domain.Dto;
using PLC.Domain.Enum;
using PLC.Domain.Models;

namespace PLC.Domain.ScheduledTasks.Strategy.Read;
/// <summary>
/// 读取的基类
/// </summary>
public abstract class BaseRead
{
   
    /// <summary>
    /// 分组标识
    /// </summary>
    public abstract EnumReadGroup ReadGroup { get; protected set; }
    /// <summary>
    /// 读取对应配置的数据
    /// </summary>
    /// <param name="readWriteNet">plc客户端</param>
    /// <param name="readConfigList">配置列表</param>
    /// <param name="plcReadModel">输出的生产数据</param>
    /// <param name="plcConfig">所有的配置</param>
    public abstract void Read(IReadWriteNet readWriteNet, PLCConfig plcConfig, List<DtoDataConfig> readConfigList,PLCReadModel plcReadModel);

    /// <summary>
    /// 对读取的状态数据进行解析
    /// </summary>
    /// <param name="value"></param>
    /// <param name="dataConfig"></param>
    /// <returns></returns>
    protected string GetValueDescription(string value, DtoDataConfig dataConfig)
    {
        var description = string.Empty;
        if (dataConfig.DataDescriptionList == null || dataConfig.DataDescriptionList.Count == 0)
        {
            return description;
        }
        var descriptionItem = dataConfig.DataDescriptionList.FirstOrDefault(p => p.Value == value);
        if (descriptionItem != null)
        {
            description = descriptionItem.Description;
        }
        return description;
    }
}